/*******************************************************************************
Paper: Does the Production Approach to Markup Estimation Match a Stylized Fact?
Description: Production function estimation to obtain output elasticity of labor
Author: Tove Forsbacka
Last Updated: 15 February 2026
*******************************************************************************/

* Setup and environment control 
clear
set more off
capture log close 
version 18.5
*ssc install acfest

* Define path and load the data
*cd "PROJECT_PATH"
use "bokslut_clean.dta"

* Drop the two largest regions (Stockholm and Gothenburg)
drop if stockholm == 1 | goteborg == 1

* Log of variables
gen y = log(dNTOMS)	
gen l = log(dPERSKOS)
gen k = log(dMATANLSU)
gen m = log(dINTINPUT)

* Set panel
xtset ORGNR year, yearly

* Production function estimation to recover output elasticity of labor
gen OUTEL = 0 
label variable OUTEL "Output elasticity of labor

foreach var of varlist market_hairdresser market_driving market_grocery market_taxi {
acfest y if `var' == 1, free(l) state(k) proxy(m) i(ORGNR) t(year)
replace OUTEL = _b[l] if `var' == 1
}

keep SNI2007_1 OUTEL
bysort SNI2007_1: gen dup = _n
drop if dup>1
drop dup

* Saving the data
save "outputelasticity.dta", replace

